package com.study.mike.common.utils;


import lombok.Data;

import java.util.Map;
import java.util.Objects;

/**
 * @author KangHui
 * @Date 2022/8/8 10:07
 */
@Data
public class MyTreeNode<T> implements MyNode<T> {
    private static final long serialVersionUID = 1L;
    private T id;
    private T parentId;
    private T checked;
    private CharSequence name;
    private Comparable<?> weight = 0;
    private Map<String, Object> extra;


    public MyTreeNode() {
    }

    public MyTreeNode(T id, T parentId, T checked, String name, Comparable<?> weight) {
        this.id = id;
        this.checked = checked;
        this.parentId = parentId;
        this.name = name;
        if (weight != null) {
            this.weight = weight;
        }

    }

    @Override
    public T getId() {
        return this.id;
    }

    @Override
    public MyTreeNode<T> setId(T id) {
        this.id = id;
        return this;
    }


    @Override
    public T getParentId() {
        return this.parentId;
    }

    @Override
    public MyTreeNode<T> setParentId(T parentId) {
        this.parentId = parentId;
        return this;
    }

    @Override
    public T getChecked() {
        return this.checked;
    }

    @Override
    public MyTreeNode<T> setChecked(T checked) {
        this.checked = checked;
        return this;
    }

    @Override
    public CharSequence getName() {
        return this.name;
    }

    @Override
    public MyTreeNode<T> setName(CharSequence name) {
        this.name = name;
        return this;
    }

    @Override
    public Comparable<?> getWeight() {
        return this.weight;
    }

    @Override
    public MyTreeNode<T> setWeight(Comparable<?> weight) {
        this.weight = weight;
        return this;
    }

    public Map<String, Object> getExtra() {
        return this.extra;
    }

    public MyTreeNode<T> setExtra(Map<String, Object> extra) {
        this.extra = extra;
        return this;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        } else if (o != null && this.getClass() == o.getClass()) {
            MyTreeNode<?> treeNode = (MyTreeNode) o;
            return Objects.equals(this.id, treeNode.id);
        } else {
            return false;
        }
    }

    @Override
    public int hashCode() {
        return Objects.hash(new Object[]{this.id});
    }
}
